<template>
	<view class="container">
		<input v-model="userInput" placeholder="说点什么..." />
		<button @click="sendMessage">发送</button>
		<ua-markdown :source="aiResponse" />
	</view>
</template>

<script>
import { chatWithAI } from '../../utils/apiService.js';

export default {
	data() {
		return {
			userInput: '',
			aiResponse: ''
		};
	},
	methods: {
		//我是大帅哥
		async sendMessage() {
			if (!this.userInput.trim()) return;

			try {
				const response = await chatWithAI(this.userInput);
				this.aiResponse = response.choices[0].message.content; // 假设 API 返回包含这个结构
				this.userInput = ''; // 清空输入框
			} catch (error) {
				uni.showToast({
					title: '错误: 无法获取 AI 响应',
					icon: 'none'
				});
			}
		}
	}
};
</script>

<style>
/* 在这里添加样式 */
.container {
	padding: 20px;
}
</style>
